<template>
  <div>
    <Popup
      v-model="showPicker"
      round
      position="bottom"
      :title="title"
      :close-on-click-overlay="false"
      class="relative Popup pt-18px px-16px"
    >
      <span class="title">选择品类</span>
      <Picker
        ref="Picker"
        :columns="categorylist"
        @cancel="showPicker = false"
        :show-toolbar="false"
        value-key="name"
      />
      <popupAction @cancel="close" @confirm="confirm"></popupAction>
    </Popup>
  </div>
</template>

<script>
import { Picker, Popup, Toast } from "vant";
import popupAction from "./popup_action.vue";
import { category } from "@/services/business/dict.js";
export default {
  props: {
    title: {
      default: "选择品类",
      type: String,
    },
  },
  components: {
    Picker,
    Popup,
    popupAction,
  },
  data() {
    return {
      showPicker: false,
      categorylist: [], //品类列表
    };
  },
  created() {
    this.get_category();
  },
  methods: {
    // 获取品类列表
    get_category() {
      category()
        .then((res) => {
          this.categorylist = res.children;
        })
        .catch((err) => {
          Toast(err.errMessage || err.message);
        });
    },
    open(data) {
      if (data.Indexes) {
        this.$refs.Picker.setIndexes(data.Indexes);
      }
      this.showPicker = true;
    },
    close() {
      this.showPicker = false;
      this.$emit("closeSlection");
    },
    confirm() {
      let arr = [];
      this.$refs.Picker.getValues().forEach((el) => {
        arr.push({ id: el.id, name: el.name, level: el.level });
      });     
      this.$emit("confirmSel", {
        value: arr,
        Indexes: this.$refs.Picker.getIndexes(),
      });
      this.showPicker = false;
    },
  },
};
</script>

<style scoped lang="scss">
.Popup {
  padding-bottom: calc(50px + env(safe-area-inset-bottom));
  .title {
    font-size: 16px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #333333;
    margin-bottom: 12px;
  }
  ::v-deep .van-picker-column__item {
    // height: 52px !important;
    .van-ellipsis {
      color: #c5cad5;
      font-size: 14px;
    }
  }
  ::v-deep .van-picker-column__item--selected {
    .van-ellipsis {
      color: #1d6fe9;
      font-weight: 600;
    }
  }
  // ::v-deep .van-picker__frame {
  //   height: 52px !important;
  // }
  // ::v-deep .van-picker-column__wrapper {
  //   transform: translate3d(0px, 102px, 0px) !important;
  // }
}
</style>
